<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <div id="app">
        <h2>人员列表过滤</h2>
        <input type="text" v-model="keyWord">
        <ul>
            <li v-for="u in filterUser" :key="u.id">
                {{u.name}} - {{u.age}} - {{u.sex}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                keyWord:'',
                persons:[
                    {id:'001',name:'马冬梅',age:19,sex:'女'},
                    {id:'002',name:'周冬雨',age:20,sex:'女'},
                    {id:'003',name:'周杰伦',age:21,sex:'男'},
                    {id:'004',name:'温兆伦',age:22,sex:'男'}
                ]
            },
            computed: {
                filterUser(){
                    if(this.keyWord) {
                        return this.persons.filter((p) => {
                            return p.name.indexOf(this.keyWord) !== -1
                        })
                    }
                    return this.persons
                }
            }
        })
    </script>
</body>
</html>